<?php
use yii\helpers\Url;
use yii\widgets\LinkPager;
?>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>铝邦CRM客户管理系统</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/setting.css"/>
    <script src="js/jquery-1.12.3.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="main-nav">
        <h3>线索</h3>
        <div class="all-clues clues-on col-sm-1">全部线索</div>
        <div class="part-clues col-sm-1">已转企业的线索</div>
        <div class="import-clues col-sm-1" data-toggle="modal" data-target="#importClues">导入线索</div>
        <div class="add-clues col-sm-1" data-toggle="modal" data-target="#addClues">+新增线索</div>
    </div>
    <!--搜索-->
    <div class="clues-search">
        <label class="search-label label-left-lg">所在地区：</label>
        <select name="" id="" class="search-select">
            <option value="0">---省份---</option>
            <?php foreach($provinceList as $value){

                ?>
                <option value="<?=$value['code']?>"><?=$value['name']?></option>
            <?php
            }?>
        </select>
        <select name="" id="" class="search-select">
            <option value="0">---城市---</option>
            <?php foreach($citiesList as $value){
                ?>
                <option value="<?=$value['code']?>"><?=$value['name']?></option>
            <?php
            }
            ?>

        </select>
        <label class="search-label label-left-sm">线索来源：</label>
        <select name="" id="" class="search-select">
            <option value="0">---请选择---</option>
            <?php foreach($clueOrginList as $value){

           ?>
                <option value="<?=$value['id']?>"><?=$value['name']?></option>
            <?php
            }
            ?>

        </select>
        <label class="search-label label-left-sm">配合度：</label>
        <select name="" id="" class="search-select">
            <option value="0">---请选择---</option>
            <?php foreach($coordination as $value){

           ?>
                <option value="<?=$value['id']?>"><?=$value['name']?></option>
            <?php
            }
            ?>

        </select>
        <label class="search-label label-left-sm">跟进状态：</label>
        <select name="" id="" class="search-select">
            <option value="0">---请选择---</option>
            <?php foreach($followTypeList as $value){

            ?>
                <option value="<?=$value['id']?>"><?=$value['name']?></option>
            <?php
            }
            ?>

        </select>
        <div class="clear"></div>
        <label class="search-label label-left-lg">未跟进时间：</label>
        <select name="" id="" class="search-select">
            <option value="0">---请选择---</option>
            <option value="1">1个月之内</option>
            <option value="2">2个月之内</option>
        </select>
        <label class="search-label label-left-sm">负责客服：</label>
        <select name="" id="" class="search-select">
            <option value="0">---部门---</option>
            <?php foreach($departmentsList as $value){

                ?>
                <option value="<?=$value['id']?>"><?=$value['departName']?></option>

                <?php foreach($value['twoGrade'] as $twoValue){
                    ?>
                    <option value="<?=$twoValue['id']?>">-<?=$twoValue['departName']?></option>
                    <?php
                    foreach($twoValue['threeGrade'] as $threeValue){
                        ?>
                        <option value="<?=$threeValue['id']?>">--<?=$threeValue['departName']?></option>
                        <?php
                        foreach($threeValue['fourGrade'] as $fourValue){
                            ?>
                            <option value="<?=$fourValue['id']?>">---<?=$fourValue['departName']?></option>
                            <?php
                            foreach($fourValue['fiveGrade'] as $fiveValue){

                                ?>

                                <option value="<?=$fiveValue['id']?>">----<?=$fiveValue['departName']?></option>
                            <?php } ?>
                            <?php
                        } ?>
                    <?php    } ?>
                <?php } ?>

            <?php } ?>
        </select>
        <select name="" id="" class="search-select">
            <option value="0">---用户---</option>
            <option value="1">思远</option>
            <option value="2">阿曼</option>
        </select>
        <div class="clear-many">清空</div>
    </div>
    <div class="clues-top-title">
        <p>已选<span class="chk-num">0</span>条线索</p>
        <div class="btn-comm btn-asg">指派</div>
        <div class="btn-comm btn-del">删除</div>
        <div class="btn-comm btn-exp">导出全部</div>
        <button class="btn-eqs">查询</button>
        <div class="input-wap">
            <select name="" id="">
                <option value="0">公司名称</option>
                <option value="1">手机号</option>
                <option value="2">电话</option>
            </select>
            <input type="text" class="search-name"/>
        </div>
    </div>
    <div class="table-wap">
        <table>
            <tr class="list-title">
                <td class="col-sm-1"><input type="checkbox" id="allCheck"/></td>
                <td class="col-sm-1">公司名称</td>
                <td class="col-sm-1">所在地区</td>
                <td class="col-sm-1">联系人</td>
                <td class="col-sm-1">电话</td>
                <td class="col-sm-1">手机</td>
                <td class="col-sm-1">线索来源</td>
                <td class="col-sm-1">配合度</td>
                <td class="col-sm-1">跟进状态</td>
                <td class="col-sm-1">最新跟进时间</td>
                <td class="col-sm-1">下次跟进时间</td>
                <td class="col-sm-1 last-col">负责客服</td>
            </tr>

                <?php foreach($clueList as $value){

                ?>
                    <tr class="chk">
                <td class="col-sm-1"><input type="checkbox" name="chk"/></td>
                <td class="col-sm-1"><a href="<?=Url::toRoute(['clue/clue-detail','clueId'=>$value['id']])?>"><?=$value['companyName']?></a></td>
                <td class="col-sm-1"><?=$value['province']['name']?>-<?=$value['city']['name']?></td>
                <td class="col-sm-1"><?=$value['contactName']?></td>
                <td class="col-sm-1">--</td>
                <td class="col-sm-1"><?=$value['cellPhone']?></td>
                <td class="col-sm-1"><?=$value['clueOrgin']['name']?></td>
                <td class="col-sm-1"><?=$value['coordinationDegree']['name']?><?php if($value['coordinationDegree']['name']){ ?>--<?php } ?></td>
                <td class="col-sm-1"><?=$value['followType']['name']?></td>
                <td class="col-sm-1"><?=date('Y-m-d H:i:s',$value['lastFollowTime'])?></td>
                <td class="col-sm-1"><?=date('Y-m-d H:i:s',$value['nextFollowTime'])?></td>
                <td class="col-sm-1 last-col"><?=$value['users']['userName']?></td>
            </tr>
                <?php
                }
                ?>
        </table>
        <?php echo LinkPager::widget([
            'pagination' => $page,
            'nextPageLabel' => '下一页',
            'prevPageLabel' => '上一页',
            'firstPageLabel' => '首页',
            'lastPageLabel' => '尾页',
        ]);
        ?>
       <!-- <p class="page-col">共<span>7</span>条，共<span>1</span>页</p>-->
    </div>
    <div class="error-kong">
        <div class="errorKong" data-toggle="modal" data-target="#addClues">
            <img src="images/unlucky.png"/>
            <p>还没有数据哦~</p>
        </div>
    </div>
    <!--添加表单-->
    <div class="modal" id="addClues" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title add-title">新增线索</h4>
                </div>
                <div class="modal-body">
                    <form id="theForm" action="" method="post">
                        <label class="modal-label"><span class="red">*</span>公司名称：</label>
                        <input type="text" id="companyName" placeholder="" name="companyName" class="modal-input"/>
                        <div class="clear"></div>
                        <label class="modal-label"><span class="red">*</span>公司地址：</label>
                        <select name="provinceId" id="provinceId" class="modal-select-sm">
                            <option value="0">--省份--</option>
                            <?php foreach($provinceList as $value){

                            ?>
                                <option value="<?=$value['code']?>"><?=$value['name']?></option>

                            <?php
                            }
                            ?>


                        </select>
                        <select name="cityId" id="cityId" class="modal-select-sm">
                            <option value="0">--城市--</option>
                            <?php foreach($provinceList as $value){

                                ?>
                                <option value="<?=$value['code']?>"><?=$value['name']?></option>

                                <?php
                            }
                            ?>
                        </select>
                        <input id="companyAddress" name="companyAddress" class="modal-input-lg left-input" type="text"/>
                        <div class="clear"></div>
                        <label class="modal-label">公司类型：</label>
                        <input id="companyType" type="text" name="companyType" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">负责客服：</label>
                        <select name="departmentId" id="departmentId" class="modal-select-sm">
                            <option value="0">--部门--</option>

                            <?php foreach($departmentsList as $value){

                                ?>
                                <option value="<?=$value['id']?>"><?=$value['departName']?></option>

                                <?php foreach($value['twoGrade'] as $twoValue){
                                    ?>
                                    <option value="<?=$twoValue['id']?>">-<?=$twoValue['departName']?></option>
                                    <?php
                                    foreach($twoValue['threeGrade'] as $threeValue){
                                        ?>
                                        <option value="<?=$threeValue['id']?>">--<?=$threeValue['departName']?></option>
                                        <?php
                                        foreach($threeValue['fourGrade'] as $fourValue){
                                            ?>
                                            <option value="<?=$fourValue['id']?>">---<?=$fourValue['departName']?></option>
                                            <?php
                                            foreach($fourValue['fiveGrade'] as $fiveValue){

                                                ?>

                                                <option value="<?=$fiveValue['id']?>">----<?=$fiveValue['departName']?></option>
                                            <?php } ?>
                                            <?php
                                        } ?>
                                    <?php    } ?>
                                <?php } ?>

                            <?php } ?>
                        </select>
                        <select name="responUserId" id="responUserId" class="modal-select-sm">
                            <option value="0">--用户--</option>

                        </select>
                        <div class="clear"></div>
                        <label class="modal-label">联系人：</label>
                        <input type="text" name="contactName" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">职务：</label>
                        <input type="text" name="job" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">电话：</label>
                        <input type="text" placeholder="电话/手机必填一个" name="phone" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">手机：</label>
                        <input type="text" placeholder="手机可以填写多个，用；隔开" name="cellphone" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">微信号：</label>
                        <input type="text" name="wechatId" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">QQ：</label>
                        <input type="text" name="QQ" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">邮箱：</label>
                        <input type="text" name="email" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">主营产品：</label>
                        <input type="text" name="mainProduct" class="modal-input-lg"/>
                        <div class="clear"></div>
                        <label class="modal-label">产品标准：</label>
                        <select name="standardId" id="standardId" class="modal-select-sm">
                            <option value="0">--请选择--</option>
                            <option value="1">国标</option>
                            <option value="2">普通</option>
                            <option value="3">国标与普通</option>
                        </select>
                        <div class="clear"></div>
                        <label class="modal-label">线索来源：</label>
                        <select name="" id="" class="modal-select-sm">
                            <option value="0">--请选择--</option>
                            <?php foreach($clueOrginList as $value){

                                ?>
                                <option value="<?=$value['id']?>"><?=$value['name']?></option>
                                <?php
                            }
                            ?>
                        </select>
                        <div class="clear"></div>
                        <label class="modal-label-bz">备注：</label>
                        <textarea name="remarks" id="remarks" cols="30" rows="10"></textarea>
                        <div class="clear"></div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="commitClue()">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal" id="importClues" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title add-title">导入线索</h4>
                </div>
                <div class="modal-body">
                    <form action="" method="post">
                        <p class="modal-em2">1、<a href="">点击下载导入线索模板</a>将要导入的数据填充到手速局导入模板文件中。</p>
                        <p class="modal-em4">注意事项：</p>
                        <p class="modal-em4">1）模板中的表头不可更改，表头行不可删除；</p>
                        <p class="modal-em4">2）除必填的列以外，不需要的列可以删除；</p>
                        <p class="modal-em4">3）单次导入的数据不超过1000条。</p>
                        <p class="modal-em2">2、数据重复时的处理方式：<span class="bold">不导入</span></p>
                        <p class="modal-em4">查重规则：公司名称</p>
                        <p class="modal-em2">3、选择要导入的数据文件</p>
                        <input type="file" class="modal-input-file"/>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary">开始导入</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            $("#addClues").modal({
                keyboard:false,
                show:false
            });
            $("#importClues").modal({
                keyboard:false,
                show:false
            });
            $("#allCheck").click(function(){
                if($(this).prop("checked")){
                    $(".chk input").prop("checked",true);
                    numChk();
                }else{
                    $(".chk input").prop("checked",false);
                    numChk();
                }
            });
            $(".chk input").click(function () {
                if($(this).prop("checked")){
                    $(this).prop("checked",true);
                    numChk();
                    var numc = $(".chk input:checked").length;
                    if(numc == $(".chk input").length){
                        $("#allCheck").prop("checked",true);
                    }
                }else{
                    $(this).prop("checked",false);
                    $("#allCheck").prop("checked",false);
                    numChk();
                }
            });
            function numChk(){
                var num = $(".chk input:checked").length;
                $(".chk-num").text(num);
            }
        })
        function commitClue(){
            var params=$('#theForm').serialize();
            var url="<?=Url::toRoute(['clue/add-clued'])?>"
            $.post(url,params,function(data){
                    var data=JSON.parse(data);
                if(data.errcode==0){
                    alert(data.errmsg);
                    window.location.reload();
                }else{
                    alert(data.errmsg);
                }
            });
        }
    </script>
</body>
</html>